package ace.j2se.l2;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * 序列化 只是保存对象的属性。不保存static静态的
 * 
 * @author guan
 * 
 */
public class SerializeStatic implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static int staticVar = 5;

	public static void main(String[] args) {
		try {
			ObjectOutputStream out = new ObjectOutputStream(
					new FileOutputStream("result.obj"));
			out.writeObject(new SerializeStatic());
			out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		SerializeStatic.staticVar = 10;
		try {
			ObjectInputStream oin = new ObjectInputStream(new FileInputStream(
					"result.obj"));
			SerializeStatic t = (SerializeStatic) oin.readObject();
			oin.close();
			System.out.println(t.staticVar);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
